<?xml version="1.0" encoding="utf-8"?>
<sqlMap namespace="Category" 
xmlns="http://ibatis.apache.org/mapping" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	
	<alias>
		<typeAlias alias="Category" type="MyBatis.DataMapper.SqlClient.Test.Domain.Category, MyBatis.DataMapper.SqlClient.Test"/>
	</alias>

  <resultMaps>
    <resultMap id="Category-result" class="Category">
      <result property="Id" column="Category_ID"/>
      <result property="Name" column="Category_Name"/>
      <result property="Guid" column="Category_Guid" nullValue="00000000-0000-0000-0000-000000000000"/>
    </resultMap>
    
    <resultMap id="resultMapScope" class="Category">
      <result property="Id" column="Category_ID"/>
    </resultMap>
    
  </resultMaps >
  
  <statements>

    <procedure id="InsertCategoryViaStoreProcedureWithReturn" parameterMap="insert-params" resultClass="int">
    		ps_InsertCategorieWithReturnValue
    </procedure>
    
    <select id="GetCategoryWithNullValueReplacementGuid" resultMap="Category-result" >
      select
      Category_ID,
      Category_Name,
      Category_Guid
      from Categories
      where Category_ID = #value#
    </select>
    
		<select id="GetCategory" parameterClass="Integer" resultClass="Category">
			select
			Category_ID as Id,
			Category_Name as Name,
			Category_Guid as Guid
			from Categories  
			where Category_ID = #value# 
		</select>
				
		<!-- Test for statement as insert -->
		<statement id="InsertCategory" parameterClass="Category" resultClass="int">
			insert into Categories  
				(Category_Name, Category_Guid) 
			values 
				(#Name#, #Guid:UniqueIdentifier#);
			select SCOPE_IDENTITY() as value
		</statement><!--Guid for Oledb, UniqueIdentifier for SqlClient,Odbc -->

    <statement id="InsertCategoryScope" parameterClass="Category" resultMap="resultMapScope">
      insert into Categories
      (Category_Name, Category_Guid)
      values
      (#Name#, #Guid:UniqueIdentifier#);
      select SCOPE_IDENTITY() as Category_ID
    </statement>
    <!--Guid for Oledb, UniqueIdentifier for SqlClient,Odbc -->

    <!-- Test for Guid Parameter Class-->
		<statement id="InsertCategoryGuidParameterClass" parameterClass="Guid" resultClass="int">
			insert into Categories  
				(Category_Name, Category_Guid) 
			values 
				('toto', #value:UniqueIdentifier#);
			select SCOPE_IDENTITY() as value
		</statement><!--Guid for Oledb, UniqueIdentifier for SqlClient,Odbc -->		
		
		<!-- JIRA 20 Test without specifying the dbtype-->
		<statement id="InsertCategoryGuidParameterClassJIRA20" parameterClass="Guid" resultClass="int">
			insert into Categories  
				(Category_Name, Category_Guid) 
			values 
				('toto', #value#);
			select SCOPE_IDENTITY() as value
		</statement>
		
		<!--  -->
		<insert id="InsertCategoryViaInsertStatement" parameterClass="Category" >
			<selectKey property="Id" type="post" resultClass="int">
				${selectKey}
            </selectKey>			
            insert into Categories  
				(Category_Name, Category_Guid) 
			values 
				(#Name#, #Guid:UniqueIdentifier#)
		</insert><!--Guid for Oledb, UniqueIdentifier for SqlClient, Odbc -->
		
		<insert id="InsertCategoryWithProperties" parameterClass="Category" >
			<selectKey property="Id" type="post" resultClass="int">
				${selectKey}
            </selectKey>			
            insert into Categories  
				(Category_Name, Category_Guid) 
			values 
				(${MyCategoryName}, #Guid:UniqueIdentifier#)
		</insert>
		
		<statement id="InsertCategoryViaParameterMap" parameterMap="InsertParam" resultClass="int">
			insert into Categories  
				(Category_Name, Category_Guid)
			values 
				(?,?);
			select SCOPE_IDENTITY() as value
		</statement>

		<statement id="InsertCategoryNull" parameterMap="insert-null-params" resultClass="int">
			insert into Categories  
				(Category_Name, Category_Guid)
			values 
				(?,?);
			select SCOPE_IDENTITY() as value
		</statement>
		
		<update id="UpdateCategoryViaParameterMap" parameterMap="UpdateParam">
			update Categories set
			Category_Name =?,
			Category_Guid = ?
			where
			Category_Id = ?
		</update>

		<procedure id="InsertCategoryViaStoreProcedureWithMap" parameterMap="insertMap-params">
			ps_InsertCategorie
		</procedure>

		<procedure id="InsertCategoryViaStoreProcedure" parameterMap="insert-params">
			ps_InsertCategorie
		</procedure>
	  
		<statement id="DynamicGuid" 
			resultClass="Category" 
			parameterClass="Category">
			select
			Category_ID as Id,
			Category_Name as Name,
			Category_Guid as Guid
			from Categories  
			<dynamic prepend="where">
				<isNotEqual prepend="and" property="Guid" compareProperty="EmptyGuid">
					Category_Guid=#Guid:UniqueIdentifier#
				</isNotEqual>
			</dynamic>
		</statement>
	</statements>
	
	<parameterMaps>
	
		<parameterMap id="insertMap-params" class="Hashtable">
			<parameter property="Id" column="Category_Id" dbType="Int" /><!-- Int for SqlClient, Obdc; Integer for Oledb -->
			<parameter property="Guid" column="Category_Guid" dbType="UniqueIdentifier"/><!--Guid for Oledb, UniqueIdentifier for SqlClient,Odbc -->
			<parameter property="Name" column="Category_Name"/>
		</parameterMap>
			
		<parameterMap id="insert-params" class="Category">
			<parameter property="Name" column="Category_Name" />
			<parameter property="Id" column="Category_Id" dbType="Int" /><!-- Int for SqlClient, Obdc; Integer for Oledb -->
			<parameter property="Guid" column="Category_Guid" dbType="UniqueIdentifier"/><!--Guid for Oledb, UniqueIdentifier for SqlClient,Odbc -->
		</parameterMap>
    
		<parameterMap id="UpdateParam" extends="InsertParam" class="Category">
			<parameter property="Id" column="Category_Id" />
		</parameterMap>	
    
		<parameterMap id="InsertParam" class="Category">
			<parameter property="Name" column="Category_Name"/>
			<parameter property="Guid" column="Category_Guid" dbType="UniqueIdentifier"/><!--Guid for Oledb, UniqueIdentifier for SqlClient,Odbc -->
		</parameterMap>

    
		<parameterMap id="insert-null-params" class="Category">
			<parameter property="Name" column="Category_Name"/>
			<parameter property="Guid" column="Category_Guid" nullValue="00000000-0000-0000-0000-000000000000" dbType="UniqueIdentifier"/><!--Guid for Oledb, UniqueIdentifier for SqlClient,Odbc -->
		</parameterMap>
		

		
		<!-- Used by generated statement -->
		
		<parameterMap id="insert-generate-params" class="Category">
			<parameter property="Name" column="Category_Name"/>
			<parameter property="Guid" column="Category_Guid" dbType="UniqueIdentifier"/><!--Guid for Oledb, UniqueIdentifier for SqlClient,Odbc -->
		</parameterMap>
		
		<parameterMap id="update-generate-params" extends="insert-generate-params" class="Category">
			<parameter property="Id" column="Category_Id" />
		</parameterMap>
		
		<parameterMap id="delete-generate-params" class="Category">
			<parameter property="Id" column="Category_Id" />
			<parameter property="Name" column="Category_Name"/>
		</parameterMap>
		
		<parameterMap id="select-generate-params" class="Category">
			<parameter property="Id" column="Category_Id" />
			<parameter property="Name" column="Category_Name"/>
			<parameter property="Guid" column="Category_Guid" dbType="UniqueIdentifier"/>
		</parameterMap>
		
	</parameterMaps>
	
</sqlMap>
